﻿//_______________________________________________________________________________________________________________________
// Copy Right (c) 2010, 2011 SapiensIT Consulting GmbH, all rights reserved
//_______________________________________________________________________________________________________________________
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT
// NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//_______________________________________________________________________________________________________________________
// PROJECT:     sapiens.at.SharePoint (SharePoint 2010/V4)
//_______________________________________________________________________________________________________________________
// VERSION:     2.0
//_______________________________________________________________________________________________________________________
// DESCRIPTION: 
//_______________________________________________________________________________________________________________________
// LICENSE:     Different licens Types apply to different file types:
//               - Source code files are governed by the MICROSOFT PUBLIC LICENSE (Ms-PL)
//               - Binary files are governed by MSDN CODE GALLERY BINARY LICENSE
//               - Documentation files are governed by CREATIVE COMMONS ATTRIBUTION 3.0 LICENSE
//
//               The licenses can be found at the projects source location.
//               If you do not agree, don't use it!
// 
//_______________________________________________________________________________________________________________________
// Start SharePoint Branding, visit http://www.cliggin.com! Visit us on http://www.sapiens.at! Tell your friends! 
//_______________________________________________________________________________________________________________________
Type.registerNamespace('Sapiens.at.SharePoint.Ribbon.PageComponent');
Sapiens.at.SharePoint.Ribbon.PageComponent = function () {
    Sapiens.at.SharePoint.Ribbon.PageComponent.initializeBase(this);
}

// the initialize function needs to be called by some script added to the page elsewhere - in the end, it does the important work 
// of calling PageManager.addPageComponent()..

Sapiens.at.SharePoint.Ribbon.PageComponent.initialize = function () {
    ExecuteOrDelayUntilScriptLoaded(Function.createDelegate(null, Sapiens.at.SharePoint.Ribbon.PageComponent.initializePageComponent), 'SP.Ribbon.js');
}

Sapiens.at.SharePoint.Ribbon.PageComponent.initializePageComponent = function() {
        var ribbonPageManager = SP.Ribbon.PageManager.get_instance();
        if (null !== ribbonPageManager) {
                ribbonPageManager.addPageComponent(Sapiens.at.SharePoint.Ribbon.PageComponent.instance);
        }
}

Sapiens.at.SharePoint.Ribbon.PageComponent.prototype = {
    init: function () { },
    getFocusedCommands: function () { // not quite sure what this means :)
        return ['Sapiens.PageComponent.Command.FieldControl.GroupCommand',
            'Sapiens.PageComponent.Command.FieldControl.TabCommand',
            'Sapiens.PageComponent.Command.FieldControl.ContextualGroupCommand',
            'Sapiens.PageComponent.Command.FieldControl.RibbonCommand'];
    },
    getGlobalCommands: function () {
        if (ribbonControllerGetGlobalCommands) {
            return ribbonControllerGetGlobalCommands();
        }
    },
    canHandleCommand: function (commandId) {
        if (ribbonControllerCanHandleCommand) {
            return ribbonControllerCanHandleCommand(commandId);
        }
    },
    handleCommand: function (commandId, properties, sequence) {
        if (commandId === 'Sapiens.PageComponent.Command.FieldControl.GroupCommand') {
            alert("Sapiens.PageComponent.Command.FieldControl.GroupCommand fired");
        }
        if (commandId === 'Sapiens.PageComponent.Command.FieldControl.TabCommand') {
            alert("Sapiens.PageComponent.Command.FieldControl.TabCommand fired");
        }
        if (commandId === 'Sapiens.PageComponent.Command.FieldControl.ContextualGroupCommand') {
            alert("Sapiens.PageComponent.Command.FieldControl.ContextualGroupCommand fired");
        }
        if (commandId === 'Sapiens.PageComponent.Command.FieldControl.RibbonCommand') {
            alert("Sapiens.PageComponent.Command.FieldControl.RibbonCommand fired");
        }
        if (ribbonControllerHandleCommand) {
            ribbonControllerHandleCommand(commandId);
        }
    },
    isFocusable: function () {
        return true;
    },
    receiveFocus: function () {
        return true;
    },
    yieldFocus: function () {
        return true;
    }
}

Sapiens.at.SharePoint.Ribbon.PageComponent.registerClass('Sapiens.at.SharePoint.Ribbon.PageComponent', CUI.Page.PageComponent);
Sapiens.at.SharePoint.Ribbon.PageComponent.instance = new Sapiens.at.SharePoint.Ribbon.PageComponent(); 

NotifyScriptLoadedAndExecuteWaitingJobs("Ribbon.PageComponent.js");